package com.kingland.wanxindong.service;

import com.kingland.wanxindong.mapper.UserModelMapper;
import com.kingland.wanxindong.model.UserModel;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;



@Service
public class UserServiceImpl implements  UserService {
    private final UserModelMapper userModelMapper;
    private final PasswordEncoder passwordEncoder;

    public UserServiceImpl(UserModelMapper userModelMapper, PasswordEncoder passwordEncoder) {
        this.userModelMapper = userModelMapper;
        this.passwordEncoder = passwordEncoder;
    }

    @Override
    public UserModel addUser(UserModel userModel) {
        userModel.setPassword(this.passwordEncoder.encode(userModel.getPassword()));
        this.userModelMapper.insert(userModel);
        return userModel;
    }
}
